<?php if(!defined('IN_FIRADIO')) {header('HTTP/1.1 403 Forbidden');exit('<h1>Access Denied</h1>');}?>
<?php $GLOBALS['script'][] = function() {?><script>
vue.data.form = {};
vue.data.disabled = false;
vue.data.api_data = {};
vue.data.api_data.rows = {};
vue.data.api_data.selects = {};
vue.methods.submit = function () {
    const that = this;
    that.ApiPost('/panel/ua/template_selects.php', that.form).then(function (data) {
        vue.data.api_data.selects = data.data.selects;
        vue.data.api_data.link_rows = data.data.link_rows;
    }, function (data) {
    })
};
vue.methods.submit_list = function () {
    const that = this;
    that.ApiPost('/panel/ua/template_list.php', that.form).then(function (data) {
        vue.data.api_data.rows = data.data.rows;
        vue.data.api_data.sumrecords = data.data.sumrecords;
    }, function (data) {
    })
};
vue.methods.checkbox_all = function(field) {
    const that = this;
    const select = that.api_data.selects[field];
    for (const key in select.options) {
        const option = select.options[key];
        option.checked = select.checkall;
    }
    that.checkbox_one(field);
};
vue.methods.checkbox_one = function(field) {
    const that = this;
    const selects = that.api_data.selects;
    that.form[field] = [];
    for (const key in selects[field].options) {
        const option = selects[field].options[key];
        if (option.checked) that.form[field].push(key);
    }
    if (that.form[field].length === 0) delete that.form[field];
    //console.log(that.form[field]);
    that.submit_list();
};
vue.methods.button_generator = function() {
    const that = this;
    if (!confirm("确定要将" + that.api_data.sumrecords + "个模板存到链接吗？")) return;
    that.ApiPost('/panel/ua/template_tolink.php', that.form).then(function (data) {
    }, function (data) {
    })
};
vue.mounted = function () {
    const that = this;
    that.submit();
    that.submit_list();
};
</script><?php }?>

<!-- Custom Tabs -->
<form v-on:submit="submit" onsubmit="return false" :disabled="disabled">
<div class="nav-tabs-custom">

    <table class="table table-bordered table-striped dataTable" style="margin-bottom:0px;">
        <tr align="center">
            <td colspan="2">UA生成界面</td>
        </tr>
        <tr align="center">
            <td style="min-width: 70px;">类型</td>
            <td align="left">选择项</td>
        </tr>
        <tr align="center" v-for="(select,key) in api_data.selects">
            <td style="vertical-align: middle;">{{select.title}}</td>
            <td align="left">
                <label><input type="checkbox" v-model="select.checkall" v-on:change="checkbox_all(key)" />全选</label>
                <label v-for="(row,name) in select.options" style="padding-left: 5px;">
                    <input type="checkbox" v-model="row.checked" v-on:change="checkbox_one(key)" />{{name}}({{row.count}})
                </label>
            </td>
        </tr>
        <tr align="center">
            <td colspan="2">
                选择链接:<select v-model="form.link_id">
                <option v-for="row in api_data.link_rows" :value="row.id">{{row.id}}:{{row.title}}</option>
                </select>
                &nbsp;&nbsp;
                <button style="font-size: 14px;" class="btn btn-default btn-xs" type="button"
                :disabled="typeof(form.link_id)!=='string'"
                v-on:click="button_generator();">将{{api_data.sumrecords}}个模板存入链接</button>
                
            </td>
        </tr>
    </table>
    <div v-for="row in api_data.rows">
        <input :value="row.template" style="width: 100%" readonly /><br />
    </div>
</div>
</form>
